package cc.eddic.pratice.programmingparadigms.streampractice.impl;

import cc.eddic.pratice.programmingparadigms.exam.QuestionBankService;
import cc.eddic.pratice.programmingparadigms.exam.domain.Answer;
import cc.eddic.pratice.programmingparadigms.exam.domain.Option;
import cc.eddic.pratice.programmingparadigms.exam.domain.Question;
import cc.eddic.pratice.programmingparadigms.exam.impl.QuestionBankServiceZyzImpl;
import cc.eddic.pratice.programmingparadigms.streampractice.QuestionAccuracy;
import cc.eddic.pratice.programmingparadigms.streampractice.QuestionAndAnswer;
import cc.eddic.pratice.programmingparadigms.streampractice.StreamPractice;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamPracticeZyzImpl implements StreamPractice {


    @Override
    public List<QuestionAndAnswer> mapToQuestionAndAnswer(List<Question> questionList) {
        return questionList.stream().map(
                question -> new QuestionAndAnswer(
                        question.getNo(),
                        question.getDescription(),

                        question.getOptions().stream().filter(
                                Option::isCorrectAnswer
                        ).findFirst().orElse(null).getChoice(),

                        question.getOptions().stream().filter(
                                Option::isCorrectAnswer
                        ).findFirst().orElse(null).getAnswer()

                )


        ).collect(Collectors.toList());


    }

    @Override
    public List<QuestionAccuracy> calculateAccuracy(List<Answer> answerList) {
        int numQuestions = 25;
        int numStudents = 9;

        int[] arr = new int[25];


        QuestionBankServiceZyzImpl serviceQuestionBank = new QuestionBankServiceZyzImpl();
        List<Question> questionList = serviceQuestionBank.importQuestions("");
        List<QuestionAccuracy> questionAccuracyList = questionList.stream().map(
             question ->    new QuestionAccuracy(question.getNo(), question.getDescription(), 0.0)
        ).collect(Collectors.toList());

        Map<Integer, Integer> map = new HashMap<>();

//
//
//        Stream<Answer> s = answerList.stream().forEach(
//                answer -> {
//                    char choice = answer.getChoice();
//                    char correctChoice = answer.getQuestion().getOptions().stream().filter(option -> option.isCorrectAnswer())
//                            .findFirst().orElse(null).getChoice();
//                    final int no = answer.getQuestion().getNo();
//
//                    if (choice == correctChoice) {
//                        if (map.containsKey(no))
//                            map.put(no, map.get(no) + 1) ;
//                        else
//                            map.put(no, 1);
//                    }
//
//
//                }
//        );


        questionAccuracyList.stream().sorted();


        return null;

    }







}
